import echarts from 'echarts';
import Moment from 'moment';

const now = new Moment();
const start = (new Moment()).subtract(3, 'month');

function getVirtulData(range, now, start) {
    const dayTime = 3600 * 24;
    const data = [];
    for (let time = start.unix(); time <= now.unix(); time += dayTime) {
        data.push([
            Moment.unix(time).format('YYYY-MM-DD'),
            (Math.random() > 0.3) ? (Math.random() * 20).toFixed(2) : 0
        ]);
    }
    return data;
}

export const calendarOption = {
    tooltip: {
        position: 'top',
        formatter(params) {
            const formatDate = params.data[0].replace('-', '年').replace('-', '月') + '日';
            return `${formatDate}<br>${params.data[1]}/24小时`
        }
    },

    visualMap: [{
        show: false,
        min: 0,
        max: 20,
        inRange: {
            color: ['#348EED'],
            opacity: [0, 1]
        },
        controller: {
            inRange: {
                opacity: [0.3, 0.6]
            },
            outOfRange: {
                color: '#ccc'
            }
        },
        calculable: true,
        seriesIndex: [0],
    }],
    calendar: {
        dayLabel: { show: false },
        monthLabel: { show: false },
        yearLabel: { show: false },
        orient: 'horizontal',
        cellSize: 'auto',
        top: 30,
        left: 80,
        right: 5,
        bottom: 10,
        range: [start.format('YYYY-MM-DD'), now.format('YYYY-MM-DD')]
    },

    series: [{
        type: 'heatmap',
        coordinateSystem: 'calendar',
        data: []
    }]
};
